
#include <scott/SByte.h>

BOOST_AUTO_TEST_SUITE( SByte_Test_Suite )

BOOST_AUTO_TEST_CASE( GetType_Test )
{
	SByteSp b = SByte::Create(5);
	BOOST_CHECK( b->GetType() == STypeByte );
}

BOOST_AUTO_TEST_CASE( GetAndSet_Test )
{
	SByteSp b = SByte::Create(5);

	BOOST_CHECK( b->Get() == 5 );

	b->Set(10);
	BOOST_CHECK( b->Get() == 10 );

	b->Set(255);
	BOOST_CHECK( b->Get() == 255 );
}

BOOST_AUTO_TEST_CASE( SByte_ToString_Test )
{
	SByteSp b = SByte::Create(0);
	BOOST_CHECK( b->ToString() == "0" );
	BOOST_CHECK( b->ToString("d") == "0" );
	BOOST_CHECK( b->ToString("x") == "0x0" );
	BOOST_CHECK( b->ToString("nx") == "0" );
	BOOST_CHECK( b->ToString("2x") == "0x00" );
	BOOST_CHECK( b->ToString("2nx") == "00" );

	b->Set(5);
	BOOST_CHECK( b->ToString() == "5" );
	BOOST_CHECK( b->ToString("d") == "5" );
	BOOST_CHECK( b->ToString("x") == "0x5" );
	BOOST_CHECK( b->ToString("nx") == "5" );
	BOOST_CHECK( b->ToString("2x") == "0x05" );
	BOOST_CHECK( b->ToString("2nx") == "05" );

	b->Set(87);
	BOOST_CHECK( b->ToString() == "87" );
	BOOST_CHECK( b->ToString("d") == "87" );
	BOOST_CHECK( b->ToString("x") == "0x57" );
	BOOST_CHECK( b->ToString("nx") == "57" );
	BOOST_CHECK( b->ToString("3x") == "0x057" );
	BOOST_CHECK( b->ToString("3nx") == "057" );

	b->Set(255);
	BOOST_CHECK( b->ToString() == "255" );
	BOOST_CHECK( b->ToString("d") == "255" );
	BOOST_CHECK( b->ToString("x") == "0xFF" );
	BOOST_CHECK( b->ToString("nx") == "FF" );
	BOOST_CHECK( b->ToString("4x") == "0x00FF" );
	BOOST_CHECK( b->ToString("4nx") == "00FF" );
}

BOOST_AUTO_TEST_CASE( SByte_Parse_Test )
{
	BOOST_CHECK_THROW( SByte::Parse(""), SParseException );

	BOOST_CHECK( SByte::Parse("0 ")->Get() == 0 );
	BOOST_CHECK( SByte::Parse(" 10")->Get() == 10 );
	BOOST_CHECK( SByte::Parse("   255 ")->Get() == 255 );

	BOOST_CHECK( SByte::Parse("0x0")->Get() == 0 );
	BOOST_CHECK( SByte::Parse("0x00 ")->Get() == 0 );
	BOOST_CHECK( SByte::Parse("0x0A")->Get() == 10 );
	BOOST_CHECK( SByte::Parse("0xFF ")->Get() == 255 );

	BOOST_CHECK_THROW( SByte::Parse("256"), SParseException );
	BOOST_CHECK_THROW( SByte::Parse(" 2 6 "), SParseException );
	BOOST_CHECK_THROW( SByte::Parse(" 1c2"), SParseException );
	BOOST_CHECK_THROW( SByte::Parse("-1"), SParseException );
	BOOST_CHECK_THROW( SByte::Parse("0xAG"), SParseException );
	BOOST_CHECK_THROW( SByte::Parse("0XE2"), SParseException );
	BOOST_CHECK_THROW( SByte::Parse("0xAE0"), SParseException );
	BOOST_CHECK_THROW( SByte::Parse(" 0xAE0F"), SParseException );
	BOOST_CHECK_THROW( SByte::Parse("'A'"), SParseException );
	BOOST_CHECK_THROW( SByte::Parse("\"Hello\""), SParseException );
	BOOST_CHECK_THROW( SByte::Parse("red"), SParseException );
	BOOST_CHECK_THROW( SByte::Parse("{}"), SParseException );
	BOOST_CHECK_THROW( SByte::Parse("{ 10 }"), SParseException );
	BOOST_CHECK_THROW( SByte::Parse("{ 'A' }"), SParseException );
	BOOST_CHECK_THROW( SByte::Parse("{ \"Hello\" }"), SParseException );
	BOOST_CHECK_THROW( SByte::Parse("{ red }"), SParseException );
}


BOOST_AUTO_TEST_SUITE_END()
